home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Freeware / Adobe Air 1.5 / AdobeAIRInstaller.exe / setup.swf / scripts / mx / states / AddChild.as next >
Encoding:
Text File  |  2008-10-29  |  5.5 KB  |  186 lines

  1. package mx.states
  2. {
  3.    import flash.display.DisplayObject;
  4.    import mx.containers.ApplicationControlBar;
  5.    import mx.containers.ControlBar;
  6.    import mx.containers.Panel;
  7.    import mx.core.Application;
  8.    import mx.core.ContainerCreationPolicy;
  9.    import mx.core.IDeferredInstance;
  10.    import mx.core.UIComponent;
  11.    import mx.core.mx_internal;
  12.    import mx.resources.IResourceManager;
  13.    import mx.resources.ResourceManager;
  14.    
  15.    use namespace mx_internal;
  16.    
  17.    public class AddChild implements IOverride
  18.    {
  19.       mx_internal static const VERSION:String = "3.0.0.0";
  20.       
  21.       mx_internal var added:Boolean = false;
  22.       
  23.       mx_internal var instanceCreated:Boolean = false;
  24.       
  25.       private var _creationPolicy:String = "auto";
  26.       
  27.       public var relativeTo:UIComponent;
  28.       
  29.       public var position:String;
  30.       
  31.       private var _target:DisplayObject;
  32.       
  33.       private var _targetFactory:IDeferredInstance;
  34.       
  35.       private var resourceManager:IResourceManager;
  36.       
  37.       public function AddChild(param1:UIComponent = null, param2:DisplayObject = null, param3:String = "lastChild")
  38.       {
  39.          resourceManager = ResourceManager.getInstance();
  40.          super();
  41.          this.relativeTo = param1;
  42.          this.target = param2;
  43.          this.position = param3;
  44.       }
  45.       
  46.       public function remove(param1:UIComponent) : void
  47.       {
  48.          var _loc2_:UIComponent = !!relativeTo ? relativeTo : param1;
  49.          if(!mx_internal::added)
  50.          {
  51.             return;
  52.          }
  53.          switch(position)
  54.          {
  55.             case "before":
  56.             case "after":
  57.                _loc2_.parent.removeChild(target);
  58.                break;
  59.             case "firstChild":
  60.             case "lastChild":
  61.             default:
  62.                if(target is ControlBar && _loc2_ is Panel)
  63.                {
  64.                   Panel(_loc2_).rawChildren.removeChild(target);
  65.                   Panel(_loc2_).createComponentsFromDescriptors();
  66.                }
  67.                else if(target is ApplicationControlBar && ApplicationControlBar(target).dock)
  68.                {
  69.                   Application(_loc2_).mx_internal::dockControlBar(ApplicationControlBar(target),false);
  70.                   Application(_loc2_).removeChild(target);
  71.                }
  72.                else if(_loc2_ == target.parent)
  73.                {
  74.                   _loc2_.removeChild(target);
  75.                }
  76.          }
  77.          mx_internal::added = false;
  78.       }
  79.       
  80.       public function initialize() : void
  81.       {
  82.          if(creationPolicy == ContainerCreationPolicy.AUTO)
  83.          {
  84.             createInstance();
  85.          }
  86.       }
  87.       
  88.       public function get target() : DisplayObject
  89.       {
  90.          if(!_target && creationPolicy != ContainerCreationPolicy.NONE)
  91.          {
  92.             createInstance();
  93.          }
  94.          return _target;
  95.       }
  96.       
  97.       public function set creationPolicy(param1:String) : void
  98.       {
  99.          _creationPolicy = param1;
  100.          if(_creationPolicy == ContainerCreationPolicy.ALL)
  101.          {
  102.             createInstance();
  103.          }
  104.       }
  105.       
  106.       public function set target(param1:DisplayObject) : void
  107.       {
  108.          _target = param1;
  109.       }
  110.       
  111.       public function apply(param1:UIComponent) : void
  112.       {
  113.          var _loc3_:String = null;
  114.          var _loc2_:UIComponent = !!relativeTo ? relativeTo : param1;
  115.          mx_internal::added = false;
  116.          if(!target)
  117.          {
  118.             return;
  119.          }
  120.          if(target.parent)
  121.          {
  122.             _loc3_ = resourceManager.getString("states","alreadyParented");
  123.             throw new Error(_loc3_);
  124.          }
  125.          switch(position)
  126.          {
  127.             case "before":
  128.                _loc2_.parent.addChildAt(target,_loc2_.parent.getChildIndex(_loc2_));
  129.                break;
  130.             case "after":
  131.                _loc2_.parent.addChildAt(target,_loc2_.parent.getChildIndex(_loc2_) + 1);
  132.                break;
  133.             case "firstChild":
  134.                _loc2_.addChildAt(target,0);
  135.                break;
  136.             case "lastChild":
  137.             default:
  138.                _loc2_.addChild(target);
  139.                if(target is ControlBar && _loc2_ is Panel)
  140.                {
  141.                   Panel(_loc2_).createComponentsFromDescriptors();
  142.                }
  143.                else if(target is ApplicationControlBar && ApplicationControlBar(target).dock && _loc2_ is Application)
  144.                {
  145.                   ApplicationControlBar(target).resetDock(true);
  146.                }
  147.          }
  148.          mx_internal::added = true;
  149.       }
  150.       
  151.       public function createInstance() : void
  152.       {
  153.          var _loc1_:Object = null;
  154.          if(!mx_internal::instanceCreated && !_target && Boolean(targetFactory))
  155.          {
  156.             mx_internal::instanceCreated = true;
  157.             _loc1_ = targetFactory.getInstance();
  158.             if(_loc1_ is DisplayObject)
  159.             {
  160.                _target = DisplayObject(_loc1_);
  161.             }
  162.          }
  163.       }
  164.       
  165.       public function set targetFactory(param1:IDeferredInstance) : void
  166.       {
  167.          _targetFactory = param1;
  168.          if(creationPolicy == ContainerCreationPolicy.ALL)
  169.          {
  170.             createInstance();
  171.          }
  172.       }
  173.       
  174.       public function get creationPolicy() : String
  175.       {
  176.          return _creationPolicy;
  177.       }
  178.       
  179.       public function get targetFactory() : IDeferredInstance
  180.       {
  181.          return _targetFactory;
  182.       }
  183.    }
  184. }
  185.  
  186.